package com.zk.algorithm.others;

import com.zk.algorithm.Utils;
import com.zk.algorithm.annotation.Easy;
import com.zk.algorithm.annotation.LeetCodeExplore;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author zk
 */
@LeetCodeExplore
@Easy
public class PascalsTriangle {

    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> result = new ArrayList<>(numRows);

        if (numRows > 0) {
            result.add(Arrays.asList(1));
        }

        if (numRows > 1) {
            result.add(Arrays.asList(1, 1));
        }

        for (int i = 2; i < numRows; i++) {
            List<Integer> upRow = result.get(i - 1);

            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);

            for (int j = 1; j < upRow.size(); j++) {
                curRow.add(upRow.get(j) + upRow.get(j - 1));
            }

            curRow.add(1);
            result.add(curRow);
        }

        return result;
    }

    public static void main(String...args) {
        Utils.println(new PascalsTriangle().generate(1));
        Utils.println(new PascalsTriangle().generate(2));
        Utils.println(new PascalsTriangle().generate(5));
    }

}
